package com.Spring.liaojp.dao;

import com.Spring.liaojp.config.DataBaseInitializer;
import com.Spring.liaojp.entity.User;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author liaojiapeng
 * &#064;date  2023/7/12 - 15:08
 * &#064;description:  用户表 数据库访问对象
 */
public class UserDao {
    private User user;

    private static final String TABLE_NAME = "user";
    private static final String USERNAME = "username";
    private static final String PASSWORD = "password";
    private static final String role = "role";

    /**
     * 插入用户信息
     * @param username 用户名
     * @param password 密码
     */
    public void insertUser(String username, String password)
    {
        String sql = "INSERT INTO " + TABLE_NAME + " (" + USERNAME + ", " + PASSWORD + ") VALUES (?, ?)";
        try (var connection = DataBaseInitializer.connection;
             var preparedStatement = connection.prepareStatement(sql)) {
             preparedStatement.setString(1, username);
             preparedStatement.setString(2, password);
             preparedStatement.executeUpdate();
        } catch (Exception ignored){}
    }
}
